
var parkOrgwsnJs = function(targetObj){
	this.sysUtils = new kendoUtils();
	this.targetObj = targetObj;
	this.init();
	return this;
};

parkOrgwsnJs.prototype={
    init:function(){
        var bindFieldArray = this.sysUtils.getBindFieldArray(this.targetObj);
        var bindFunctionArray = [{fName:"savewsnOrg",fs:this.savewsnOrg},{fName:"cancel",fs:parkTree.resetTree}];
        this.bindBaseModels = new bindBaseModel(null,bindFieldArray,bindFunctionArray,null);
        this.sysUtils.bindDoucment(this.bindBaseModels,this.targetObj,this);
        //分辨率
       /* var resolutions = Utils.getModelValueByModelKey(BASIS.VOICE_GENDER.MALE);
        Utils.createDataDictDropDownList([{div:this.targetObj.find("#resolution"),parentModelKey:BASIS.VOICE_GENDER.ROOT,select:resolutions}],this,this.loadTab());*/
        //分辨率
//        var voicegenders = Utils.getModelValueByModelKey(BASIS.VOICE_GENDER.MALE);
//        Utils.createDataDictDropDownList([{div:this.targetObj.find("#voicegender"),parentModelKey:BASIS.VOICE_GENDER.ROOT,select:voicegenders}],this);
        this.loadWsninfo();
    },
    loadWsninfo:function (e) {
        var that = this;
        that.editResult = null;
        that.isEdit = null;
        if (!isEmpty(e)) {
            that = $(e.target).data("that");
        }
        zTree == null?$.fn.zTree.init($("#tree"), setting): $.fn.zTree.getZTreeObj("tree");
        var id = zTree.getSelectedNodes()[0].id,level=zTree.getSelectedNodes()[0].level;
        var url = baseApiPath+"facilities/parkInfo";
        if(id){
            that.isEdit = true;
            url += '?isEdit='+that.isEdit+'&organizationCode='+id;
        }else{
            that.isEdit = false;
            var node = zTree.getSelectedNodes()[0].getParentNode();
            url = baseApiPath+'facilities/addOrz?isEdit='+that.isEdit+'&pid='+node.id+'&lev='+level+'&gpc=wsn';
        }
        JsonpAjax(url,null,"json",function(result){
            that.editResult = result;
            that.sysUtils.setVariantBindFieldValue(result);
            document.getElementById('value').innerHTML = document.getElementById('range').value == '' ? '50' : document.getElementById('range').value;
            that.setswitchCss();
        },false);
        parkTree.hideMask();
    },
    setswitchCss:function () {
        var that = this;
        that.targetObj.find(".checkbox input[type='checkbox']").each(function () {
            $(this).click(function(){
                this.value= this.value !=1 ? 1 : 0;
                this.checked = this.value == 1 ? true : false;
            });
            if(this.value == 1){
                this.checked=true;
            }else{
                this.checked=false;
            }
        });
    },
    loadTab:function () {
        var that = this;
        that.targetObj.find('#stTabs').carouFredSel({
            circular: false,
            items: 1,
            width: '100%',
            auto: false,
            pagination: {
                container: '#stPager',
                anchorBuilder: function( nr ) {
                    return '<a href="#">' + $(this).find('h3').text() + '</a>';
                }
            }
        });
    },
    //保存工作站信息
    savewsnOrg:function(e){
        var that =  $(e.target).data("that");
        if(validityForm(that.targetObj)){
            var parkInfo = that.sysUtils.getBindDocJson();
            var url = baseApiPath+"facilities/saveParkInfo?isEdit=" + that.isEdit;
            var sendJson=parkInfo;
            for(var o in parkInfo){
                if(o.indexOf('_') !=-1){
                    var strArray = o.substring(o.indexOf('_')+1);
                    var name = o.substring(0, o.indexOf('_'));
                    var jsonA = {};
                    jsonA[name] = that.recursionObjectName(strArray,parkInfo[o]) ;
                    delete parkInfo[o];
                    sendJson =$.extend(true,parkInfo,jsonA);
                }
            }
            JsonpAjax(url,JSON.stringify(sendJson),"json",function(result){
                    that.sysUtils.setVariantBindFieldValue(result);
                    that.isEdit=true;
                    parkTree.localUpdate(result);
            });
        }
    },
    recursionObjectName : function (strArray,val) {
        if (strArray.indexOf('_') == -1){
            var jsonC = {};
            jsonC[strArray]=val;
            return jsonC;
        }
        var name = strArray.substring(0, strArray.indexOf('_'));
        strArray = strArray.substring(strArray.indexOf('_')+1);
        var jsonB = {};
        jsonB[name] = this.recursionObjectName(strArray,val);
        return jsonB;
    },
    rangeChange:function () {
        document.getElementById('value').innerHTML = document.getElementById('range').value;
    }
}
